package com.ifighter.helper;

import com.ifighter.service.cluster.Cluster;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MyDbHelper extends SQLiteOpenHelper{

	private static final String DB_NAME  = "iFighterDB";
	private static final int DB_VERSIONE = 1;

	private String CREATE_TABLE_USER    = "CREATE TABLE IF NOT EXISTS USER (" +
			" NAME TEXT, LASTNAME TEXT, NICKNAME TEXT PRIMARY KEY, PASSWORD TEXT NOT NULL, EMAIL TEXT)";
	private String CREATE_TABLE_TEAM    = "CREATE TABLE IF NOT EXISTS TEAM (" +
			" ID_TEAM INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL)";
	private String CREATE_TABLE_CLUSTER = "CREATE TABLE IF NOT EXISTS CLUSTER (" +
			" ID_CLUSTER INTEGER PRIMARY KEY AUTOINCREMENT, TYPE TEXT UNIQUE NOT NULL)";

	public MyDbHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSIONE);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {

		db.execSQL(CREATE_TABLE_USER);
		db.execSQL(CREATE_TABLE_TEAM);
		db.execSQL(CREATE_TABLE_CLUSTER);
		
		ContentValues contentValues = null;
		contentValues = new ContentValues();
		contentValues.put("TYPE", "Allenatore");
		db.insert(Cluster.TABLE, null, contentValues);
		contentValues.clear();
		contentValues.put("TYPE", "Giocatore");
		db.insert(Cluster.TABLE, null, contentValues);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}
}